<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/7/6
 * Time: 14:09
 */

namespace App\Http\Requests;

use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
class DriverOtherRequest extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'real_name' => 'required|max:50',
            'phone' => 'required|max:11',
            'company_id' => 'required'
        ];
    }

    /**
     * 验证提示信息
     * @return array
     * @Author 姿势就是力量
     */
    public function messages()
    {
        return [
            'real_name.required' => '真实姓名不能为空',
            'real_name.max' => '真实姓名长度只能在50个字符之间',
            'phone.required' => '手机号不能为空',
            'phone.max' => '手机号格式不正确',
            'company_id.required' => '请选择所属公司',
        ];
    }


    protected function failedValidation(Validator $validator)
    {
        throw new HttpResponseException(response()->json([
            'code' => 0,
            'data' => [],
            'msg' => $validator->errors()->first()
        ], 400));
    }
}